﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using WinFormsApp1.Leo;

namespace WinFormsApp1.SuYi.week1WinForm
{
    public partial class BusinesWinFormShow : Form
    {
        public BusinesWinFormShow()
        {
            InitializeComponent();
            GetBusinesQuery();
        }

        private async void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        public int PageIndex = 1;
        public int PageSize = 5;
        public int totalPage = 0;
        public int totalCount = 0;

        public string BusinessName = "";

        private async void BusinesWinFormShow_Load(object sender, EventArgs e)
        {
            //GetBusinesQuery();
        }

        private async void GetBusinesQuery()
        {
            var pageDto = new PageDto()
            {
                PageIndex = PageIndex,
                PageSize = PageSize,
                BusinessName = BusinessName
            };
            var items1 = await HttpClientHelper.RequestUrl<PageDto, ApiResultFY2<List<BusinessDto>>>(URLCommon.Url2, "/Week1Get/QueryBusub", HttpClientHelper.MethodType.POST, pageDto);

            this.dataGridView1.DataSource = items1.Data.list;
            totalCount = items1.Data.totalCount;
            totalPage = items1.Data.totalPage;
        }

        public class BusinessDto
        {
            /// <summary>
            /// 企业名称
            /// </summary>
            public string BusinessName { get; set; }
            /// <summary>
            /// 企业简称
            /// </summary>
            public string BusinessAbbreviation { get; set; }
            /// <summary>
            /// 详情地址
            /// </summary>
            public string DetailedAddress { get; set; }
            /// <summary>
            /// 企业电话
            /// </summary>
            public string BusinessPhone { get; set; }
            /// <summary>
            /// 负责人
            /// </summary>
            public string BusinessDuty { get; set; }
            /// <summary>
            /// 是否删除
            /// </summary>
            //public bool IsDelete { get; set; }
            /// <summary>
            /// 行业名称
            /// </summary>
            public string IndustrytagName { get; set; }
            /// <summary>
            /// 区名称
            /// </summary>
            public string AreaName { get; set; }
            /// <summary>
            /// 市名称
            /// </summary>
            public string CitysName { get; set; }
            /// <summary>
            /// 省名称
            /// </summary>
            public string ProvibceName { get; set; }
        }



        private void button1_Click(object sender, EventArgs e)
        {
            BusinessName = textBox1.Text;
            GetBusinesQuery();
        }

        public class PageDto
        {
            /// <summary>
            /// 页码
            /// </summary>
            public int PageIndex { get; set; }
            /// <summary>
            /// 条数
            /// </summary>
            public int PageSize { get; set; }
            /// <summary>
            /// 企业名称
            /// </summary>
            public string BusinessName { get; set; }
        }

        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton1_Click(object sender, EventArgs e)
        {
            PageIndex = 1;
            GetBusinesQuery();
        }
        /// <summary>
        /// 尾页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton4_Click(object sender, EventArgs e)
        {
            PageIndex = totalPage;
            GetBusinesQuery();
        }
        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton2_Click(object sender, EventArgs e)
        {
            if (PageIndex > 1)
            {
                PageIndex--;
            }
            else
            {
                //弹框提示
                MessageBox.Show("已经第一页了");
            }
            GetBusinesQuery();
        }
        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton3_Click(object sender, EventArgs e)
        {
            if (PageIndex == totalPage)
            {
                //弹框提示
                MessageBox.Show("已经最后一页了");
            }
            else
            {
                PageIndex ++ ;
            }
            GetBusinesQuery();
        }
    }
}
